package com.ysw.validator.controller;

import com.ysw.dto.ResponseResult;
import com.ysw.validator.bean.ValidatorV1Bean;
import com.ysw.validator.dynamic_validator.Employee;
import com.ysw.validator.validate_collections.Element;
import com.ysw.validator.validate_collections.ValidateList;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @ClassName ValidatorController
 * @Description 测试controller
 * @Author ysw
 * @Date 2022/5/12 19:45
 */
@RestController
@Validated
public class ValidatorController {
    /**
     * 简单测试
     * @param bean
     * @return
     */
    @RequestMapping("/v/testSimple")
    public ResponseResult testSimple(@Validated(value = {ValidatorV1Bean.UpdateGroup.class}) @RequestBody ValidatorV1Bean bean){
        return ResponseResult.success();
    }

    /**
     * 自定义注解测试
     * @param
     * @return
     */
    @RequestMapping("/v/testCustom")
    public ResponseResult testSimple3(@Validated @RequestBody ValidatorV1Bean bean){
        return ResponseResult.success();
    }


    @RequestMapping("/v/testSimple1")
    @Valid
    public ResponseResult testSimple1(@NotNull String id,@NotBlank String name){
        return ResponseResult.success();
    }

    /**
     * 校验list分组校验
     * @param elements
     * @return
     */
    @RequestMapping("/v/testValidList")
    public ResponseResult testValidList(@Validated(Element.ELementUpdate.class) @NotEmpty @RequestBody ValidateList<Element> elements){
        List<Element> list = elements.getList();
        return ResponseResult.success();
    }



    /**
     * 校验list分组校验
     * @param employee
     * @return
     */
    @RequestMapping("/v/testBeanField")
    public ResponseResult testBeanField(@Validated @RequestBody Employee employee){
        return ResponseResult.success();
    }


}